<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="lib/react.development.js"></script>
    <script src="lib/react-dom.development.js"></script>
    <script src="lib/babel.min.js"></script>
    <script src="lib/prop-types.min.js"></script>
</head>
<body>
    <div id="root"></div>
    <script type="text/babel">
     let {Component} = React

    class Tick extends Component{
        constructor(props){
            super(props);
            this.state = {
                time:new Date()
            }
        }
        componentWillMount(){
            console.log('组件挂载前')
        }

        componentDidMount(){
            console.log('组件挂载后')
            this.timer = setInterval(()=>{
                this.setState({
                    time:new Date()
                })
            },1000)
        }
        componentWillUpdate(){
            console.log('组件更新前')
        }
        componentDidUpdate(){
            console.log('组件更新后')
        }
        componentUnMount(){
            console.log('组件销毁')
            clearInterval(this.timer)
        }

        render(){
            return (<div>
                <h2>{this.state.time.toLocaleTimeString()}</h2>
                
            </div>)
        }
    }

    ReactDOM.render(
        <Tick />,
        document.querySelector('#root')
    )

    </script>
</body>
</html>